package com.demo.understandmvc.handler.httpRequestHandler;

import java.io.IOException;
import java.util.Collections;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;

@SpringBootApplication
public class App {

	public static void main(String[] args) throws IOException {
		SpringApplication.run(App.class, args);
	}

	// 访问http://127.0.0.1:8080/demo/httpRequestHandler
	@Bean
	public SimpleUrlHandlerMapping myHttpRequestHandler() {
		SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping();
		// 设置优先级最高
		mapping.setOrder(Ordered.HIGHEST_PRECEDENCE);
		// 配置了handler，还需要把handler注册到mapping中，才能被查找到
		mapping.setUrlMap(Collections.singletonMap("httpRequestHandler", new MyHttpRequestHandler()));
		return mapping;
	}

}
